<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">

<script type="text/javascript" src="/lib/layer/2.4/layer.js" xmlns="http://www.w3.org/1999/html"></script>

<body class="easyui-layout">
<!-- 说明 字符串：Project，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
	<!-- 主表  -->
	<table id="project_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/project-list/-2/1/20',
					  method:'get',
					  toolbar:'#tb',
					  loadMsg : '数据加载中',
					  onDblClickRow:onDblClickRow,
					  onRowContextMenu: onRowContextMenu,
					  onLoadSuccess:function(data){
                            $('.download').linkbutton({plain:true,iconCls:'icon-download'});
                        },
					  showFooter: true" >
		<#--<#include "/common/thead.html">-->
        <thead>
        <tr>
            <th data-options="field:'id',width:40,align:'center',formatter:idFormatter">下载</th>
            <th data-options="field:'uuid',width:40,align:'center',hidden:'true'"></th>
            <th data-options="field:'proId',width:200,align:'center'">项目编号</th>
            <th data-options="field:'proName',width:340,align:'center' ">项目名称</th>
            <th data-options="field:'proState',width:100,align:'center',formatter:stateFormatter ">项目状态</th>
            <#--<th data-options="field:'proCategory',width:150,align:'center',formatter:proCategoryFormatter ">项目分类</th>-->
            <th data-options="field:'proManager',width:100,align:'center' ">项目负责人</th>
            <#--<th data-options="field:'proApprovalTime',width:150,align:'center' ">立项时间</th>-->
            <#--<th data-options="field:'proRealInvestmentTime',width:150,align:'center' ">项目实际投资时间</th>-->
            <#--<th data-options="field:'proTuichuTime',width:150,align:'center' ">项目退出时间</th>-->
            <#--<th data-options="field:'proInvestmentMoney',width:150,align:'center' ">投资金额</th>-->
            <#--<th data-options="field:'proPaymentMoney',width:150,align:'center' ">付款金额</th>-->
            <#--<th data-options="field:'proProportion',width:100,align:'center' ">股权比例</th>-->
            <#--<th data-options="field:'proContent',width:300,align:'center' ">合同主要条款</th>-->
            <#--<th data-options="field:'proCompanyMain',width:300,align:'center' ">公司主营</th>-->
            <#--<th data-options="field:'proCompanyNature',width:150,align:'center' ">公司性质</th>-->
            <#--<th data-options="field:'proCompanyCondition',width:300,align:'center' ">公司情况</th>-->
            <#--<th data-options="field:'proCompanyRequire',width:300,align:'center' ">公司需求</th>-->
        </tr>
        </thead>
	</table>
</div>


<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
	<div>
        项目名称:
        <input class="easyui-textbox" name="proName"id="proName">
        项目状态:
        <input class="easyui-combobox" name="state"id="state"
               data-options="
				url : '/constants/proj_state',
				method: 'get',
				valueField:'key',
				textField:'value',
				">
		投资开始时间:
		<input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" id="proRealInvestmentBeginTime" style="width:120px">
        <span style="color: blue;font-size: 10px">-</span>
        投资截止时间:
        <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" id="proRealInvestmentEndTime" style="width:120px">
        <br/><br/>
		退出开始时间:
		<input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" id="proTuichuBeginTime" style="width:120px">
       <span style="color: blue;font-size: 10px">-</span>
        退出截止时间:
        <input class="easyui-datebox" data-options="formatter:dateformatter,parser:dateparser" id="proTuichuEndTime" style="width:120px">
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
	</div>
    <div style="margin:5px 0;"></div>
    <#include "/common/button.html">
</div>


<!-- 右键 -->
<div id="right_click" class="easyui-menu" style="width:120px;">
    <div onclick="query()" data-options="iconCls:'icon-add'">查看</div>
</div>

<script type="text/javascript">
    function onRowContextMenu(e,row){
        e.preventDefault();
        var node = $('#project_table').datagrid('getSelected');
        if(node){
            $('#right_click').menu('show',{
                left: e.pageX,
                top: e.pageY
            });
        }
    }

    function query() {
        var row = $('#project_table').datagrid('getSelected');
        var id = row.id;
        var title = row.proName
        var url = '/query-project-detail/'+id;
        var index = layer.open({
            type: 2,
            title:title,
            area: ['420px', '240px'], //宽高
            closeBtn: 1, //不显示关闭按钮
            anim: 2,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            content: url
        });
        layer.full(index);
    }
</script>

<script>
    function dateformatter(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
    }
    function dateparser(s){
        if (!s) return new Date();
        var ss = (s.split('-'));
        var y = parseInt(ss[0],10);
        var m = parseInt(ss[1],10);
        var d = parseInt(ss[2],10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
            return new Date(y,m-1,d);
        } else {
            return new Date();
        }
    }

</script>

<script>
    function stateFormatter(value) {
        var res = '';
        $.ajax({
            url:'/constants/proj_state/'+value,
            method:'get',
            async:false,
            success:function(data){
                res = data;
            }
        })
        return res;
    }

    function proCategoryFormatter(value) {
        var res = '';
        $.ajax({
            url:'/constants/proj_category/'+value,
            method:'get',
            async:false,
            success:function(data){
                console.log(data);
                res = data;
            }
        })
        return res;
    }
</script>

<script type="text/javascript">
    $("#searchByParameter").click(function(){
        var state = $("#state").val();
        var proName = $("#proName").val();
        var proRealInvestmentBeginTime = $("#proRealInvestmentBeginTime").val();
        var proRealInvestmentEndTime = $("#proRealInvestmentEndTime").val();
        var proTuichuBeginTime = $("#proTuichuBeginTime").val();
        var proTuichuEndTime = $("#proTuichuEndTime").val();
        if("" == state || null == state){
            state = -2;
        }
        // -2查询所有项目
        var handler = '/project-list/'+state+'/1/20?&proName='+proName
            +"&proRealInvestmentBeginTime="+proRealInvestmentBeginTime+
            "&proRealInvestmentEndTime="+proRealInvestmentEndTime+"&proTuichuBeginTime="+proTuichuBeginTime+
            "&proTuichuEndTime="+proTuichuEndTime;
        $('#project_table').datagrid('options').url = handler;
        $('#project_table').datagrid('reload');
    });


    function onDblClickRow(rowIndex,rowData){
        var id = rowData.id;
        var title = rowData.proName;
        $.ajax({
            url:'/queryPojectById/'+id,
			method:'get',
			async:'false',
			success:function(res){
                var url = "";
                var state = res.proState;
				if(state == "0"){
					url = '/project-ruku-view/'+id;
				}else if(state == "1"){
                    url = '/project-lixiang-view/'+id;
				}else if(state == "2"){
                    url = '/project-juece-view/'+id;
                }else if(state == "3"){
                    url = '/project-touzi-view/'+id;
                }else if(state == "4"){
                    url = '/project-touhouZT-view/'+id;
                }else if(state == "5"){
                    url = '/project-tuichu-view/'+id;
                }else if(state == "6"){
                    url = '/project-touhouZT-view/'+id;
				} else if(state == "-1"){
                    if(res.proLocation == "ruku"){
                        url = '/project-ruku-view/'+id;
					}else
                    if(res.proLocation == "lixiang"){
                        url = '/project-lixiang-view/'+id;
                    }else
                    if(res.proLocation == "juece"){
                        url = '/project-juece-view/'+id;
                    }else
                    if(res.proLocation == "touzi"){
                        url = '/project-touzi-view/'+id;
                    }else
                    if(res.proLocation == "touhou"){
                        url = '/project-touhouZT-view/'+id;
                    }else
                    if(res.proLocation == "tuichu"){
                        url = '/project-tuichu-view/'+id;
                    }else if(res.proLocation == "jijintouhou"){
                        url = '/project-touhouZT-view/'+id;
					} else
					{
					    url = '/project-yichang-view/'+id;
					}
                }else if(state == "7"){
                    if(res.proLocation == "ruku"){
                        url = '/project-ruku-view/'+id;
                    }else
                    if(res.proLocation == "lixiang"){
                        url = '/project-lixiang-view/'+id;
                    }else
                    if(res.proLocation == "juece"){
                        url = '/project-juece-view/'+id;
                    }else
                    if(res.proLocation == "touzi"){
                        url = '/project-touzi-view/'+id;
                    }else
                    if(res.proLocation == "touhou"){
                        url = '/project-touhouZT-view/'+id;
                    }else
                    if(res.proLocation == "tuichu"){
                        url = '/project-tuichu-view/'+id;
                    }else if(res.proLocation == "jijintouhou"){
                        url = '/project-touhouZT-view/'+id;
                    } else
                    {
                        url = '/project-yichang-view/'+id;
                    }
                }

                var index = layer.open({
                    type: 2,
                    title:title,
                    area: ['420px', '240px'], //宽高
                    closeBtn: 1, //不显示关闭按钮
                    anim: 2,
                    maxmin: true,
                    shadeClose: true, //开启遮罩关闭
                    content: url
                });
                layer.full(index);
			}
        });

    }
</script>

<script type="text/javascript">
    function idFormatter(value,row) {
        var button ='';
        $.ajax({
            url: '/project-check-download/' + value,
            async: false,
            success: function (data) {
                if (data == 'download') {
                    button += '<a href="#" class="download" title="打包下载" onclick=\'down(' + value + ')\'></a> ';
                }
            }
        });
        return button;
    }
    function  proCategoryFormatter(val) {
        var result = '';
        $.ajax({
            url : '/constants/proj_category/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }
    function proStateFormatter(val) {
        var result = '';
        $.ajax({
            url : '/constants/proj_state/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }
    function userIdFormatter(val){
        var result = '';
        $.ajax({
            url : '/user-get/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }
    function proCampanyidFormatter(val){
        var result = '';
        $.ajax({
            url : '/company-get/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }
</script>

<!-- 按钮操作 -->
<script type="text/javascript">

    function down(val){
        window.location = "/project-zip/"+val;
    }
    //查看项目信息
	$('#projectInfo').click(function(){
            var node = $('#project_table').datagrid('getSelected');
            if(null != node && "" != node){
                var id = node.id;
                var url = '/projectInfo-validate/'+id;
                var index = layer.open({
                    title:'项目明细',
                    type: 2,
                    area: ['700px', '450px'],
                    fixed: true, //不固定
                    maxmin: true,
                    content: url
                });
                layer.full(index);
            }else {
                layer.msg("请选择数据！");
            }
    });
</script>

<!-- 分页 -->
<script type="text/javascript">
	$(function(){
		var p = $('#project_table').datagrid().datagrid('getPager');
		p.pagination({
			pageSize: 20, //每页显示的记录条数，默认为10
			pageList: [20, 40, 60], //可以设置每页记录条数的列表
			onSelectPage: function (pageNumber, pageSize) {
			    if(pageNumber==0){
			        pageNumber = 1;
                }
                var state = $("#state").val();
                var proName = $("#proName").val();
                var proRealInvestmentBeginTime = $("#proRealInvestmentBeginTime").val();
                var proRealInvestmentEndTime = $("#proRealInvestmentEndTime").val();
                var proTuichuBeginTime = $("#proTuichuBeginTime").val();
                var proTuichuEndTime = $("#proTuichuEndTime").val();
                if("" == state || null == state){
                    state = -2;
                }
                // -2查询所有项目
                var handler = '/project-list/'+state+'/'+pageNumber+'/'+pageSize+'?&proName='+proName
                    +"&proRealInvestmentBeginTime="+proRealInvestmentBeginTime+
                    "&proRealInvestmentEndTime="+proRealInvestmentEndTime+"&proTuichuBeginTime="+proTuichuBeginTime+
                    "&proTuichuEndTime="+proTuichuEndTime;
                $('#project_table').datagrid('options').url = handler;
                $('#project_table').datagrid('reload');
			}
		});
	})
</script>